/**
 * Created by yoyoyk on 2017/3/8.
 */
import React , {Component}from 'react';
import { Modal, Button } from 'antd';
import Confirm from '../../common/Confirm'
import Select from '../../common/Select'
import UpdateDepartmentBatchMutation from "./mutation/UpdateDepartmentBatchMutation";
import Relay from "react-relay";

/*业务平台>人员管理>编辑部门>批量修改部门*/

export default class Muchmodifypart extends React.Component {
    constructor(props){
        super(props);
        this.state = {
            visible: false,
            uidlist:[],
            departname:{},
            partid :0,
            departmentforchoose:[],
        }
        this.Style={};
    }

    componentWillMount() {
        this.Style.muchmodifypartview={
            textAlign:"center",
            display:"block",
            border:"3px solid green"
        }
        this.Style.muchmodifypartview.width = 400;
        this.Style.muchmodifypartview.height = 200;
        this.Style.muchmodifypartview.fontSize = 30;

        this.Style.muchmodifypartview={
            width:"634px",
            height:"44px",
            paddingLeft:"18px",
            lineHeight:"44px",
            display:"block",
            background:"#f2f2f2",
            marginBottom:49
        }


    }

    state = { visible: false }
    showModal = () => {
        this.setState({
            visible: true,
        });
    }
    handleOk = (e) => {
        console.log(e);
        this.setState({
            visible: false,
        });
    }
    handleCancel = (e) => {
        console.log(e);
        this.setState({
            visible: false,
        });
    }

    createuser(){
        // console.warn(JSON.stringify(this.state.departmentforchoose));
        // console.dir(this.state.departname)
        let name
        if(this.refs.partname.state.value==''){
            name =  this.refs.partname.state.defaultValue
        }else{
            name = this.refs.partname.state.value;
        }

        // console.warn(this.props.deparmentc[name])



        Relay.Store.commitUpdate(
            new UpdateDepartmentBatchMutation({
                enterpriseId: '26',
                depId:this.props.deparmentc[name],
                ids:this.state.uidlist.join(',')
            }),
            {
                onFailure: () => {

                },
                onSuccess: (response) => {
                    let errorCode = response.updateDepartmentBatch.updateDepartmentBatch.errorCode
                    if(errorCode=='0'){
                        let inde = this.state.departmentforchoose.indexOf(name)
                        this.props.onchose(name,inde)
                    }
                }
            }
        )
        ;

    }
    
    render(){
        return (
            <Modal visible={this.state.visible} onOk={this.handleOk} onCancel={this.handleCancel} style={{width:"634px",height:"240px",display:"block"}} title={"批量修改部门"}>
                <p style={{width:200,marginLeft:80}}>员工总数<span>{this.state.uidlist.length}</span>人</p>
                <span style={{position:"absolute",display:"block",left:80,top:42}}>职务</span>
                <Select var oArr={this.state.departname} style={{display:"inlineBlock", width:338,height:30,display:"inlineBlock",marginTop:20,marginLeft:124}} defaultValue={this.props.defaultValue} ref={'partname'}/>
                <Confirm tcontext="确认修改" style={{width:130,height:30,display:"block",color:"#fff",fontSize:"16px",marginTop:60,marginLeft:220}} touch={this.createuser.bind(this)}/>
            </Modal>
        )
    }
}

var oArr1=[
    {text:"请选择部门",value:"0"},
    {text:"前台",value:"1"},
    {text:"后台",value:"2"},
    {text:"管理",value:"3"}
]



